<include file="public@header"/>
</head>
<body>
<div class="wrap js-check-wrap">
    <form method="post" id="listordersForm" class="js-ajax-form" action="{:url('AdminCategory/listorders')}">
        <table class="table table-hover table-bordered table-list">
            <thead>
            <tr>
                <th width="16">
                    <!-- <label>
                        <input type="checkbox" class="js-check-all" data-direction="x" data-checklist="js-check-x">
                    </label> -->
                </th>
                <th width="50">ID</th>
                <th>
                    名称
                    &nbsp;
                    <input class="form-control"  type="text" id="searchName"
                                 style="width: 200px;height: 26px;display: inline;" value="{$searchName}" placeholder="输入完整名称并按回车键">
                </th>
            </tr>
            </thead>
            <tbody>
            {$categories_tree}
            </tbody>
        </table>
    </form>

    <form id="sqselectForm" action="{:url('AdminCategory/sqselect')}" method="post" style="display: none;">
        <input type="text" id="hiddenInput" name="searchName" value="">
        <input type="text" name="ids" value="{$ids}">
        <input type="text" name="yxid" value="{$yxIds}">
        <button type="submit">提交另一个表单</button>
    </form>
</div>
<script src="__STATIC__/js/admin.js"></script>
<script>
    document.addEventListener('DOMContentLoaded', (event) => {
        const input = document.getElementById('searchName');
        const myForm = document.getElementById('listordersForm');
        const anotherForm = $('#sqselectForm');

        // 监听 input 的 keyup 事件
        input.addEventListener('keyup', (event) => {
            if (event.key === 'Enter') {
                event.preventDefault(); // 阻止当前表单的默认提交

                // 将输入的内容复制到另一个表单的输入框中
                const anotherInput = document.getElementById('hiddenInput');
                anotherInput.value = input.value;

                // 提交另一个表单
                anotherForm.submit();
            }
        });

        // 可选：防止当前表单的默认提交
        myForm.addEventListener('submit', (event) => {
            event.preventDefault(); // 阻止表单提交
            console.log('当前表单提交被阻止');
            // 在这里可以添加你的自定义处理逻辑
        });
    });


    $('.data-item-tr').click(function (e) {

        console.log(e);
        var $this = $(this);
        if ($(e.target).is('input')) {
            return;
        }

        var $input = $this.find('input');
        if ($input.is(':checked')) {
            $input.prop('checked', false);
        } else {
            $input.prop('checked', true);
        }
    });

    function confirm() {
        var selectedCategoriesId   = [];
        var selectedCategoriesName = [];
        var selectedCategories     = [];
        $('.js-check:checked').each(function () {
            var $this = $(this);
            selectedCategoriesId.push($this.val());
            selectedCategoriesName.push($this.data('parentname') +' '+ $this.data('name'));

            selectedCategories.push({
                id: $this.val(),
                name: $this.data('name')
            });
        });

        return {
            selectedCategories: selectedCategories,
            selectedCategoriesId: selectedCategoriesId,
            selectedCategoriesName: selectedCategoriesName
        };
    }
</script>
</body>
</html>